package orderlayer

import (
	"dhfshop/models/misc"
	"dhfshop/models/org"
	"dhfshop/models/member"
	"dhfshop/utils/math"
	//"github.com/astaxie/beego"
)

func PreventSubmitOrder(appId string, memberId int64) (bool, error) {
	if appCfg, err := misc.GetWxAppCfgByAppIdAndName(appId, "ADD_TRADE_TYPE"); err == nil {
	    if appCfg.Value == "2" {
	       if _, err = org.GetFxDistributor(memberId); err != nil {
		       return true, nil
		   }
	    }
	}
	return false, nil
}

func CalcDeliveryDistance(addressId int64, storeId int64) (float64, error) {
	distance := 0.0
	deliverAddr, err := member.GetDeliverAddrById(addressId)
	if err != nil {
	    return distance, err
	}
	store, err := org.GetStoreById(storeId)
	if err != nil {
	    return distance, err
	}
	distance = math.Sphere(deliverAddr.Longitude,deliverAddr.Latitude,store.Longitude,store.Latitude)
	//beego.Debug("delivery:Longitude,Latitude:",deliverAddr.Longitude,deliverAddr.Latitude)
	//beego.Debug("store:Longitude,Latitude:",store.Longitude,store.Latitude)
	//beego.Debug("distance:",distance)
	return distance, nil
}
